VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form MCM 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "WMR1250 Configuration Manager"
   ClientHeight    =   5295
   ClientLeft      =   150
   ClientTop       =   840
   ClientWidth     =   8175
   Icon            =   "MCM.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5295
   ScaleWidth      =   8175
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command2 
      Caption         =   "Command2"
      Height          =   195
      Left            =   240
      TabIndex        =   7
      Top             =   6360
      Width           =   975
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   7200
      Top             =   0
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.Timer HIDTimer 
      Enabled         =   0   'False
      Interval        =   200
      Left            =   7680
      Top             =   0
   End
   Begin VB.TextBox HIDResult 
      Height          =   285
      Left            =   3000
      TabIndex        =   4
      Top             =   5400
      Width           =   5055
   End
   Begin VB.CommandButton Download 
      Caption         =   "Download"
      Height          =   255
      Left            =   1440
      TabIndex        =   3
      Top             =   5400
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Default"
      Height          =   255
      Left            =   240
      TabIndex        =   2
      Top             =   5400
      Width           =   975
   End
   Begin MSComctlLib.ListView ListView1 
      Height          =   4455
      Left            =   2760
      TabIndex        =   1
      Top             =   720
      Width           =   5295
      _ExtentX        =   9340
      _ExtentY        =   7858
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      FullRowSelect   =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   0
      NumItems        =   0
   End
   Begin MSComctlLib.ImageList ImageList1 
      Left            =   840
      Top             =   2040
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      MaskColor       =   12632256
      _Version        =   393216
   End
   Begin MSComctlLib.TreeView TreeView1 
      Height          =   4455
      Left            =   120
      TabIndex        =   0
      Top             =   720
      Width           =   2535
      _ExtentX        =   4471
      _ExtentY        =   7858
      _Version        =   393217
      LabelEdit       =   1
      Style           =   7
      ImageList       =   "imlItems"
      Appearance      =   1
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin MSComctlLib.Toolbar tbToolBar 
      Align           =   1  'Align Top
      Height          =   600
      Left            =   0
      TabIndex        =   6
      Top             =   0
      Width           =   8175
      _ExtentX        =   14420
      _ExtentY        =   1058
      ButtonWidth     =   1032
      ButtonHeight    =   1005
      AllowCustomize  =   0   'False
      Appearance      =   1
      Style           =   1
      ImageList       =   "imlToolbarIcons"
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   6
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "New"
            Object.ToolTipText     =   "New"
            ImageIndex      =   1
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "Open"
            Object.ToolTipText     =   "Open"
            ImageIndex      =   2
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "Save"
            Object.ToolTipText     =   "Save"
            ImageIndex      =   3
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "Download"
            Object.ToolTipText     =   "Download Settings"
            ImageIndex      =   4
         EndProperty
         BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "Upload"
            Object.ToolTipText     =   "Upload Settings"
            ImageIndex      =   5
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.ImageList imlToolbarIcons 
      Left            =   3960
      Top             =   5640
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   32
      ImageHeight     =   32
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   11
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":0442
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":0556
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":066A
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":077E
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":0BD0
            Key             =   ""
         EndProperty
         BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":1022
            Key             =   ""
         EndProperty
         BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":1474
            Key             =   ""
         EndProperty
         BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":18C8
            Key             =   ""
         EndProperty
         BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":1D1A
            Key             =   ""
         EndProperty
         BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":216E
            Key             =   ""
         EndProperty
         BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":25C2
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.ImageList imlItems 
      Left            =   4800
      Top             =   5640
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   6
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":26D6
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":2B2A
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":2F7E
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":33D2
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":3826
            Key             =   ""
         EndProperty
         BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "MCM.frx":3C7A
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin VB.Label HIDLable 
      Caption         =   "Label1"
      Height          =   255
      Left            =   240
      TabIndex        =   5
      Top             =   5760
      Width           =   3255
   End
   Begin VB.Menu file 
      Caption         =   "File"
      Begin VB.Menu new 
         Caption         =   "New"
      End
      Begin VB.Menu open 
         Caption         =   "Open"
      End
      Begin VB.Menu save 
         Caption         =   "Save"
      End
      Begin VB.Menu saveas 
         Caption         =   "Save As"
      End
      Begin VB.Menu exit 
         Caption         =   "Exit"
      End
   End
   Begin VB.Menu settings 
      Caption         =   "Settings"
      Begin VB.Menu upload 
         Caption         =   "Upload"
      End
      Begin VB.Menu dnload 
         Caption         =   "Download"
      End
   End
   Begin VB.Menu help 
      Caption         =   "Help"
      Begin VB.Menu about 
         Caption         =   "About"
      End
   End
End
Attribute VB_Name = "MCM"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const ACKCMD = 2
Const ETX = 3
Private MsgByte As Byte
Private MsgIndex As Long
Private HasMoreResponse As Boolean
Private MoreRcvLen As Long
Private IDTECHFmt As Boolean

Private ToRdrBfr(400) As Byte
Private CheckSum As Byte
Private ToRdrBfrPtr As Long
Private ToRdrBfrLen As Long
Private MoreToRdrLen As Long
Private HasMoreToRdr As Boolean
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hWndOwner As Long, _
    ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, _
    ByVal pszPath As String) As Long
Private Type EMID
    cb As Long
    abID As Byte
End Type
Private Type ITEMIDLIST
    mkid As EMID
End Type
Private Const MAX_PATH As Integer = 260

Public id As String
Public idname As String
Public IDvalue As String
Public connected As Integer
Public fname As String
Public fpath As String
Public H10 As String 'Terminal Type
Public H11 As String 'Beep Setting
Public H12 As String 'Character Delay
Public H13 As String 'Track Selection
Public H14 As String 'Polling Interval
Public H15 As String 'Data Output Format
Public H16 As String 'UIC, MagTek
Public H17 As String 'Track Separator
Public H19 As String 'Send Option
Public H1A As String 'MSR Reading
Public H1B As String 'DT Enable Send
Public H1D As String 'Decoding Direction
Public H1F As String 'Review All Settings
Public H21 As String 'Terminator
Public H22 As String 'Firmware
Public H23 As String 'USB HID Fmt
Public H24 As String 'Foreign KB
Public H25 As String 'Obsolescent encryption
Public H34 As String 'Track 1 Prefix
Public H35 As String 'Track 2 Prefix
Public H36 As String 'Track 3 Prefix
Public H37 As String 'Track 1 Suffix
Public H38 As String 'Track 2 Suffix
Public H39 As String 'Track 3 Suffix
Public H41 As String 'Baud Rate
Public H42 As String 'Data Bit
Public H43 As String 'Data Parity
Public H44 As String 'Hand Shake
Public H45 As String 'Stop Bit
Public H47 As String 'XOn Character
Public H48 As String 'XOff Character
Public H49 As String 'PAN to not mask
Public H4A As String 'PAN to not mask
Public H4B As String 'mask the PAN with this character
Public H4C As String 'encryption type
Public H4D As String 'Std, OPOS or JPOS
Public H4E As String 'device serial #
Public H50 As String 'mask or display expiration date
Public H54 As String '8 byte hex not stored in EEPROM
Public H55 As String 'include mod10 check digit
Public H56 As String 'DES Key Value
Public H57 As String 'AES Key Value
Public H58 As String 'DUKPT
Public H5C As String 'HashOptID
Public H5D As String 'HexCaseID
Public H60 As String 'LRC character
Public H61 As String 'Track 1 7 Bit Start Char
Public H62 As String 'Track 1 6 Bit Start Char
Public H63 As String 'Track 1 5 Bit Start Char
Public H64 As String 'Track 2 7 Bit Start Char
Public H65 As String 'Track 2 5 Bit Start Char
Public H66 As String 'Track 3 7 Bit Start Char
Public H67 As String 'Track 3 6 Bit Start Char
Public H68 As String 'Track 3 5 Bit Start Char
Public H69 As String 'Track 1 End Sentinel
Public H6A As String 'Track 2 End Sentinel
Public H6B As String 'Track 3 End Sentinel
Public H6C As String 'Track 1 error code
Public H6D As String 'Track 2 error code
Public H6E As String 'Track 3 error code
Public H72 As String 'JIS T12 SS/ES
Public H73 As String 'JIS T3 SS/ES
Public H77 As String 'feature option setting
Public H7A As String 'Turn off Beep
Public H7B As String 'check for track sync bits
Public H7E As String 'Security Level ID
Public H84 As String 'encryption options
Public H85 As String 'encrypt structure
Public H86 As String 'clear/mask data options
Public HD2 As String 'Preamble
Public HD3 As String 'Postamble
Public HFA As String 'DE Added Field
Public HFB As String 'DE Search Cmd
Public HFC As String 'DE Send Cmd

Public cmdstring As String 'Command String


Private Sub SetDefault()
id = "0"
H10 = "30" ''0'('0'~'2','4'~'6') | PC/AT, Scan Code Set 2, 1, 3, PC/AT with external Keyboard and PC/AT without External Keyboard
H11 = "32" ''2'('0'~'4') | Beep volume high and frequency high
H12 = "30" 'only in KB '0'('0'~'5') | 2 ms inter-character delay
H13 = "30" ''0'('0'~'9') | Any Track 0->any; 1-7->bit 1 tk1, bit 2 tk2; bit 3 tk3. '8'->tk1-2; '9'->tk2-3
H14 = "01" '1 (1 ~ 255) | USB HID Polling Interval
H15 = "30" ''0'('0'~'2') | Unitech Format
H16 = "59" 'H'59' | Refer to MiniMag RS232 User's Manual
H17 = "0D" 'CR/Enter 0 for Port Powered IV | CR for RS232, Enter for KB any character supported except 00 which means none.
H19 = "31" ''1'('0'~'F') '5' for Port Powered IV | Sentinel and Account Number Control
H1A = "31" ''1'('0'~'2') | Enable MSR Reading '0' MSR disable; '2' Buffer Mode
H1B = "30" ''0'('0','1','3') | Data Editing Control
H1D = "31" ''1'('0'~'3') | Decoding in both direction; '0' Raw data '2' forward '3' reverse
H21 = "0D"
H23 = "38" 'only in USB, reset all not effected
H24 = "30" 'only in KB
H34 = "00" '"00"
H35 = "00"
H36 = "00"
H37 = "00"
H38 = "00"
H39 = "00"
H41 = "35"
H42 = "30"
H43 = "30"
H44 = "30"
H45 = "30"
H47 = "11"
H48 = "13"
H49 = "04"
H4A = "04"
H4B = "2A"
H4C = "31" 'read only
H4D = "30"
H4E = "08\46\46\46\46\46\46\46\46" 'read only
H50 = "30"
H55 = "30"
H58 = "31"
H5C = "37"
H5D = "31" 'only in KB
H60 = "30"
H61 = "25"
H62 = "25"
H63 = "3B"
H64 = "25"
H65 = "3B"
H66 = "25"
H67 = "21"
H68 = "3B"
H69 = "3F"
H6A = "3F"
H6B = "3F"
H6C = "25"
H6D = "3B"
H6E = "2B"
H72 = "7F"
H73 = "7F"
H77 = "30" 'read only
H7A = "30"
H7B = "30"
H7E = "30" 'read only
H84 = "08"
H85 = "30"
H86 = "07"
HD2 = "00"
HD3 = "00"
HFA = "00"
HFB = "00"
HFC = "08\00\FF\00\FF\00\FF\00\FF"
End Sub

Public Sub setcmdstring()
    Dim X As Integer
    cmdstring = "\53"
    cmdstring = cmdstring & _
                "\10\01\" & H10 & _
                "\11\01\" & H11 & _
                "\12\01\" & H12 & _
                "\13\01\" & H13 & _
                "\14\01\" & H14 & _
                "\17\01\" & H17 & _
                "\19\01\" & H19 & _
                "\1A\01\" & H1A & _
                "\1D\01\" & H1D
    cmdstring = cmdstring & _
                "\21\01\" & H21 & _
                "\23\01\" & H23 & _
                "\24\01\" & H24
    If (H34 = "00") Then
    cmdstring = cmdstring & "\34\01\00"
    Else
    X = (Len(H34) + 1) / 3
    cmdstring = cmdstring & "\34\0" & X + 1 & "\0" & X & "\" & H34
    End If
    If (H35 = "00") Then
    cmdstring = cmdstring & "\35\01\00"
    Else
    X = (Len(H35) + 1) / 3
    cmdstring = cmdstring & "\35\0" & X + 1 & "\0" & X & "\" & H35
    End If
    If (H36 = "00") Then
    cmdstring = cmdstring & "\36\01\00"
    Else
    X = (Len(H36) + 1) / 3
    cmdstring = cmdstring & "\36\0" & X + 1 & "\0" & X & "\" & H36
    End If
    If (H37 = "00") Then
    cmdstring = cmdstring & "\37\01\00"
    Else
    X = (Len(H37) + 1) / 3
    cmdstring = cmdstring & "\37\0" & X + 1 & "\0" & X & "\" & H37
    End If
    If (H38 = "00") Then
    cmdstring = cmdstring & "\38\01\00"
    Else
    X = (Len(H38) + 1) / 3
    cmdstring = cmdstring & "\38\0" & X + 1 & "\0" & X & "\" & H38
    End If
    If (H39 = "00") Then
    cmdstring = cmdstring & "\39\01\00"
    Else
    X = (Len(H39) + 1) / 3
    cmdstring = cmdstring & "\39\0" & X + 1 & "\0" & X & "\" & H39
    End If
    cmdstring = cmdstring & _
                "\49\01\" & H49 & _
                "\4A\01\" & H4A & _
                "\4B\01\" & H4B & _
                "\4D\01\" & H4D
    cmdstring = cmdstring & _
                "\50\01\" & H50
    cmdstring = cmdstring & _
                "\60\01\" & H60 & _
                "\61\01\" & H61 & _
                "\62\01\" & H62 & _
                "\63\01\" & H63 & _
                "\64\01\" & H64 & _
                "\65\01\" & H65 & _
                "\66\01\" & H66 & _
                "\67\01\" & H67 & _
                "\68\01\" & H68 & _
                "\69\01\" & H69 & _
                "\6A\01\" & H6A & _
                "\6B\01\" & H6B & _
                "\6C\01\" & H6C & _
                "\6D\01\" & H6D & _
                "\6E\01\" & H6E
    cmdstring = cmdstring & _
                "\84\01\" & H84 & _
                "\85\01\" & H85 & _
                "\86\01\" & H86
    If (HD2 = "00") Then
        cmdstring = cmdstring & "\D2\01\00"
    Else
        X = (Len(HD2) + 1) / 3
        If (X = 15) Then
            cmdstring = cmdstring & "\D2\" & Hex(X + 1) & "\0" & Hex(X) & "\" & HD2
        Else
            cmdstring = cmdstring & "\D2\0" & Hex(X + 1) & "\0" & Hex(X) & "\" & HD2
        End If
    End If
    If (HD3 = "00") Then
        cmdstring = cmdstring & "\D3\01\00"
    Else
        X = (Len(HD3) + 1) / 3
        If (X = 15) Then
            cmdstring = cmdstring & "\D3\" & Hex(X + 1) & "\0" & Hex(X) & "\" & HD3
        Else
            cmdstring = cmdstring & "\D3\0" & Hex(X + 1) & "\0" & Hex(X) & "\" & HD3
        End If
    End If
    'MsgBox (cmdstring)
End Sub

Private Sub about_Click()
    IDvalue = 2
    Status.Show vbModal, Me
End Sub

Private Sub Command1_Click()
    Dim CommandOrg, Command As String
    Dim I As Integer
    Dim temp As String
    
    CommandOrg = "\53\18" 'txtCommand.Text
    Command = ""
        
    For I = 2 To Len(CommandOrg)
        temp = Mid(CommandOrg, I, 1)
        If temp = Chr(92) Then
            temp = " "
        End If
        Command = Command & temp
    Next I
    
    Call SendHIDCommand(Command)
'ListView1.ListItems("beep").SubItems(1) = "Low"
'If ListView1.ListItems("interchar").SubItems(1) = "10 ms" Then
'    ListView1.ListItems("interchar").SubItems(1) = "100 ms"
'Else
'    ListView1.ListItems("interchar").SubItems(1) = "10 ms"
'End If
'ListView1.ListItems ("interblock")

End Sub


Public Sub SendHIDCommand(cmd As String)
    Dim Temp1, Temp2 As String
    Dim I As Integer
    Dim HasMore As Boolean
    
    If FatalError <> "" Then
        HIDLable.Caption = "Error - " & FatalError
        Status.Label1.Caption = "Error - " & FatalError
        Exit Sub
    End If
    
    If HidDevice = INVALID_HANDLE_VALUE Then
        DetectDevice
        If HidDevice = INVALID_HANDLE_VALUE Then
            HIDLable.Caption = "Searching for reader..."
            Status.Label1.Caption = "Searching for reader..."
            connected = 0
            Exit Sub
        End If
        If FatalError <> "" Then
            HIDLable.Caption = "Error - " & FatalError
            Status.Label1.Caption = "Searching for reader..."
            Exit Sub
        End If
    End If

    InitCmd

    If Not FillToRdrBfr(cmd) Then
        Exit Sub
    End If
    FillTrxBfr
    SendCmd
    While (HasMoreToRdr)
        FillTrxBfr
        SendCmd
    Wend
    
    'CompleteString.Caption = HexStrToCharStr(ToRdrBfr, ToRdrBfrLen)
    
    Sleep 60
    If ToRdrBfr(2) = 82 And ToRdrBfr(3) = 31 Then
    HasMore = True
    Temp1 = ""
    GetResponse
    While (HasMore)
        Temp1 = Temp1 & Mid(ByteArrayToHexStr(FtrRptRcvBfr, Capabilities.FeatureReportByteLength), 5) & " "
        GetResponse
        HasMore = False
        For I = 2 To Capabilities.FeatureReportByteLength - 1
            If FtrRptRcvBfr(I) <> 0 Then
            HasMore = True
            End If
        Next I
    Wend
    HIDResult.Text = Temp1
    ElseIf ToRdrBfr(2) = 82 And ToRdrBfr(3) = 34 Then
    HasMore = True
    HIDResult.Text = ""
    GetResponse
    Temp1 = ByteStrToChar(FtrRptRcvBfr, 3, Capabilities.FeatureReportByteLength - 1)
    HIDResult.Text = HIDResult.Text & Temp1
    While (HasMore)
        GetResponse
        HasMore = False
        For I = 1 To Capabilities.FeatureReportByteLength - 1
            If FtrRptRcvBfr(I) <> 3 Then
            HasMore = True
            Else
            HasMore = False
            Exit For
            End If
        Next I
        If (HasMore) Then
        Temp1 = ByteStrToChar(FtrRptRcvBfr, 1, Capabilities.FeatureReportByteLength - 1)
        Else
        Temp1 = ByteStrToChar(FtrRptRcvBfr, 1, I - 1)
        End If
        HIDResult.Text = HIDResult.Text & Temp1
    Wend
    Else
    GetResponse
    HIDResult.Text = "\" & Mid(ByteArrayToHexStr(FtrRptRcvBfr, Capabilities.FeatureReportByteLength), 5, 2)
    End If
    
End Sub

'These subroutines to put command string into the usb controller sending buffer
Private Function FillToRdrBfr(cmd As String) As Boolean

    Dim NextByteResult As String
    Dim DataIndex As Long
    Dim FtrRptIndex As Long
    Dim I As Integer
    
    FillToRdrBfr = True
    MsgIndex = 1
    DataIndex = 3
    
     For I = 1 To 399
        ToRdrBfr(I) = 0
    Next
    ToRdrBfr(1) = ACKCMD
    CheckSum = ToRdrBfr(1)
    
    ToRdrBfrPtr = 2
    
    NextByteResult = "GotByte"
    Do While NextByteResult = "GotByte"
        NextByteResult = GetNextMsgByte(cmd)
        If NextByteResult = "GotByte" Then
            ToRdrBfr(ToRdrBfrPtr) = MsgByte
            CheckSum = CheckSum Xor ToRdrBfr(ToRdrBfrPtr)
            ToRdrBfrPtr = ToRdrBfrPtr + 1
        ElseIf NextByteResult = "BadMsg" Then
            FillToRdrBfr = False
            Exit Function
        End If
    Loop
 
    ToRdrBfr(ToRdrBfrPtr) = &H3
    CheckSum = CheckSum Xor ToRdrBfr(ToRdrBfrPtr)
    ToRdrBfrPtr = ToRdrBfrPtr + 1
    ToRdrBfr(ToRdrBfrPtr) = CheckSum
    ToRdrBfrLen = ToRdrBfrPtr
    ToRdrBfrPtr = 1
    
End Function

Private Function GetNextMsgByte(cmd As String) As String

    Dim ascval As Integer
    Dim GotChar As Boolean
    Dim TmpByte As Byte
    
    GetNextMsgByte = "MsgDone"
    MsgByte = 0
    GotChar = False
    
    Do While MsgIndex <= Len(cmd)
        ascval = Asc(Mid(cmd, MsgIndex, 1))
        MsgIndex = MsgIndex + 1
        If ascval = 9 Or ascval = 10 Or ascval = 13 Or ascval = 32 Then
            If GotChar Then
                GetNextMsgByte = "GotByte"
                Exit Function
            End If
        ElseIf (ascval >= 48 And ascval <= 57) Or (ascval >= 65 And ascval <= 72) Or _
        (ascval >= 97 And ascval <= 102) Then
            If ascval >= 65 And ascval <= 72 Then
                TmpByte = ascval - 55
            ElseIf ascval >= 97 And ascval <= 102 Then
                TmpByte = ascval - 87
            Else
                TmpByte = ascval - 48
            End If
            
            If GotChar Then
                MsgByte = MsgByte * 16 + TmpByte
                GetNextMsgByte = "GotByte"
                Exit Function
            Else
                GotChar = True
                MsgByte = TmpByte
            End If
        Else
            GetNextMsgByte = "BadMsg"
            Exit Function
        End If
    Loop
    
    If GotChar Then
        GetNextMsgByte = "GotByte"
    End If
End Function

Private Sub FillTrxBfr()

    Dim NextByteResult As String
    Dim DataIndex As Long
    Dim FtrRptIndex As Long
    
    MsgIndex = 1
    DataIndex = 3
    FtrRptTrxBfr(0) = 0
    For FtrRptIndex = 1 To Capabilities.FeatureReportByteLength - 1
        FtrRptTrxBfr(FtrRptIndex) = ToRdrBfr(ToRdrBfrPtr)
        ToRdrBfrPtr = ToRdrBfrPtr + 1
    Next
    If ToRdrBfrPtr > ToRdrBfrLen Then
        HasMoreToRdr = False
    Else
        HasMoreToRdr = True
    End If
End Sub

'These functions are for the data type conversion
Function HexStrToCharStr(HexStr, HexLen) As String
    
    Dim I As Integer
    Dim Char1, Char2 As Byte
   
    HexStrToCharStr = ""
    For I = 1 To HexLen
        Char1 = HexStr(I)
        If Char1 = Asc("\") Then
            HexStrToCharStr = HexStrToCharStr & "\"
        End If
        
        If (32 <= Char1) And (Char1 <= 126) Then
            HexStrToCharStr = HexStrToCharStr & "\" & Hex(Char1)
        Else
            If Len(Hex(Char1)) < 2 Then
                HexStrToCharStr = HexStrToCharStr & "\0" & Hex(Char1)
            Else
                HexStrToCharStr = HexStrToCharStr & "\" & Hex(Char1)
            End If
        End If
    Next I
End Function

Function ByteArrayToHexStr(ByRef ByteArray() As Byte, ByVal ArrayLen As Long) As String

    Dim I As Long
    Dim HexStr As String
    
    ByteArrayToHexStr = ""
    For I = 0 To ArrayLen - 1

        HexStr = Hex(ByteArray(I))
        If Len(HexStr) = 1 Then
            HexStr = "0" & HexStr
        End If
        ByteArrayToHexStr = ByteArrayToHexStr & " " & HexStr

    Next I
End Function

Function ByteStrToChar(ByteStr, StartPosition, StopPosition) As String
    
    Dim I As Integer
   
    ByteStrToChar = ""
    For I = StartPosition To StopPosition
        ByteStrToChar = ByteStrToChar & Chr(ByteStr(I))
    Next I
End Function

Private Sub Command2_Click()
    parsecmd ("\53\10\01\30\11\01\32\12\01\30\13\01\30\14\01\01\17\01\0D\19\01\31\1A\01\31\1D\01\31\21\01\0D\23\01\38\24\01\30\34\04\03\31\31\31\35\04\03\33\33\33\36\01\00\37\04\03\32\32\32\38\04\03\34\34\34\39\01\00\49\01\04\4A\01\04\4B\01\2A\4D\01\30\50\01\30\60\01\30\61\01\25\62\01\25\63\01\3B\64\01\25\65\01\3B\66\01\25\67\01\21\68\01\3B\69\01\3F\6A\01\3F\6B\01\3F\6C\01\25\6D\01\3B\6E\01\2B\84\01\08\85\01\30\86\01\07\D2\01\00\D3\01\00")
End Sub

Private Sub Download_Click()
    Dim CommandOrg, Command As String
    Dim I As Integer
    Dim temp As String
    setcmdstring
    CommandOrg = cmdstring '"\52\22" 'txtCommand.Text
    'MsgBox cmdstring, vbInformation
    'HIDResult.Text = CommandOrg
    Command = ""
        
    For I = 2 To Len(CommandOrg)
        temp = Mid(CommandOrg, I, 1)
        If temp = Chr(92) Then
            temp = " "
        End If
        Command = Command & temp
    Next I
    
    Call SendHIDCommand(Command)
End Sub

Private Sub exit_Click()
    Unload Me
End Sub

Public Sub Form_Load()
    fname = ""
    fpath = ""
    IDvalue = 0
    InitUSB
'    HIDTimer.Enabled = True
    HIDTimer.Interval = 200
SetDefault
inittree
Dim slist As ListItem
ListView1.ColumnHeaders.Add , , "Attribute", 2500
ListView1.ColumnHeaders.Add , , "Data"
End Sub

Private Sub listview1_DblClick()
    'setcmdstring
    'MsgBox cmdstring
    If id <> "0" Then
        Edit.Show vbModal, Me
    End If
End Sub

Private Sub listview1_ItemClick(ByVal Item As MSComctlLib.ListItem)
    id = Item.Key
    idname = Item.Text
End Sub

Private Sub new_Click()
    'MsgBox "Do you want to save current setting?", vbYesNoCancel, "Scanner Configuration Manager"
    SetDefault
    ListView1.ListItems.Clear
    TreeView1.Nodes.Clear
    inittree
    TreeView1.Nodes(1).EnsureVisible
    TreeView1.Nodes(2).EnsureVisible
    TreeView1.Nodes(3).EnsureVisible
    TreeView1.Nodes(4).EnsureVisible
    TreeView1.Nodes(5).EnsureVisible
    'Call Form_Load
End Sub

Private Sub open_Click()
    CommonDialog1.FileName = ""
    CommonDialog1.Flags = cdlOFNFileMustExist
    CommonDialog1.Filter = "Configure(*.cfg)|*.cfg"
    CommonDialog1.InitDir = fGetSpecialFolder(5) '"C:\"
    CommonDialog1.ShowOpen
    If CommonDialog1.FileName = "" Then
    Else
        fname = CommonDialog1.FileName
        'MsgBox fname
        Open fname For Input As #2
            Line Input #2, cmdstring
        Close #2
        'MsgBox cmdstring
        If (parsecmd(cmdstring)) Then
            'setcmdstring
            TreeView1.Nodes.Clear
            ListView1.ListItems.Clear
            inittree
        Else
            MsgBox ("Invalid Config File")
            Call open_Click
        End If
    End If
End Sub

Private Sub save_Click()
    'CommonDialog1.flag = dlOFNOverwritePrompt
    'MsgBox fname & "|" & Dir(fname)
    On Error GoTo errhandler
    If (fname <> "" Or Dir(fname) = "") Then
        'fname = CommonDialog1.filename
        setcmdstring
        Open fname For Output As #2
            Print #2, cmdstring
        Close #2
    Else
        CommonDialog1.Flags = cdlOFNOverwritePrompt
        CommonDialog1.Filter = "Configure(*.cfg)|*.cfg"
        CommonDialog1.InitDir = fGetSpecialFolder(5) '"C:\"
        CommonDialog1.ShowSave
        If CommonDialog1.FileName = "" Then
        Else
            fname = CommonDialog1.FileName
            'MsgBox fname
            setcmdstring
            Open fname For Output As #2
                Print #2, cmdstring
            Close #2
        End If
    End If
    Exit Sub
errhandler:
    Select Case Err
    Case 32755 '  Dialog Cancelled
        MsgBox "You cancelled the dialog box"
    Case Else
        MsgBox "Unexpected error. Err " & Err & " : " & Error
    End Select
End Sub

Private Sub saveas_Click()
    On Error GoTo errhandler
    CommonDialog1.Flags = cdlOFNOverwritePrompt
    CommonDialog1.Filter = "Configure(*.cfg)|*.cfg"
    CommonDialog1.InitDir = fGetSpecialFolder(5) '"C:\"
    CommonDialog1.ShowSave
    If CommonDialog1.FileName = "" Then
    Else
        fname = CommonDialog1.FileName
        'MsgBox fname
        setcmdstring
        Open fname For Output As #2
            Print #2, cmdstring
        Close #2
    End If
    Exit Sub
errhandler:
    Select Case Err
    Case 32755 '  Dialog Cancelled
        MsgBox "You cancelled the dialog box"
    Case Else
        MsgBox "Unexpected error. Err " & Err & " : " & Error
    End Select
End Sub

Private Sub security_Click()
    IDvalue = 3
    Status.Show vbModeless, Me
End Sub

Private Sub tbToolBar_ButtonClick(ByVal Button As MSComctlLib.Button)
    On Error Resume Next
    Select Case Button.Key
        Case "New"
            new_Click
        Case "Open"
            open_Click
        Case "Save"
            save_Click
        Case "Download"
            dnload_Click
        Case "Upload"
            upload_Click
    End Select
End Sub

'Private Sub TreeView1_DblClick()
Public Sub TreeView1_Collapse(ByVal Node As MSComctlLib.Node)
    'TreeView1.Nodes("Root").Text = " + Current Settings"
    ListView1.ListItems.Clear
'If TreeView1.Nodes("Root").Text = "    Current Settings" Then
'TreeView1.Nodes("Root").Text = " + Current Settings"
'Else
'TreeView1.Nodes("Root").Text = "    Current Settings"
'End If
End Sub

Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
     'TreeView1.Nodes("Root").Text = "    Current Settings"
        ListView1.ListItems.Clear
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    Dim temp As String
    If Node.Key <> "Root" Then
        'MsgBox Node.Key
    End If
    If Node.Key = "Child1" Then
        ListView1.ListItems.Clear
        ListView1.ListItems.Add , "beep", "Beep Tone"
        ListView1.ListItems.Add , "delay", "Character Delay"
        temp = conv("H11")
        ListView1.ListItems.Item(1).ListSubItems.Add , , temp
        temp = conv("H12")
        ListView1.ListItems.Item(2).ListSubItems.Add , , temp
    End If
    If Node.Key = "Child2" Then
        ListView1.ListItems.Clear
        ListView1.ListItems.Add , "language", "Language"
        ListView1.ListItems.Add , "sendoptionid", "Function Key Output"
        temp = conv("H24")
        ListView1.ListItems.Item(1).ListSubItems.Add , , temp
        temp = conv("H190")
        ListView1.ListItems.Item(2).ListSubItems.Add , , temp
    End If
    If Node.Key = "Child3" Then
        ListView1.ListItems.Clear
        ListView1.ListItems.Add , "pollingintervalid", "USB HID KB Interval"
        temp = conv("H14")
        ListView1.ListItems.Item(1).ListSubItems.Add , , temp
        ListView1.ListItems.Add , "usbmode", "USB Mode"
        temp = conv("H23")
        ListView1.ListItems.Item(2).ListSubItems.Add , , temp
    
    End If
    If Node.Key = "Child4" Then
        ListView1.ListItems.Clear
        ListView1.ListItems.Add , "terminator", "Terminator"
        ListView1.ListItems.Add , "sendsentinel", "Send Start/Stop Sentinel"
        ListView1.ListItems.Add , "trackselection", "Track Selection"
        ListView1.ListItems.Add , "track2account", "Track 2 Account Number Only"
        ListView1.ListItems.Add , "separator", "Separator Character"
        ListView1.ListItems.Add , "7bitsentinel", "Track 1 Start Sentinel"
        ListView1.ListItems.Add , "6bitsentinel", "Track 2 Start Sentinel"
        ListView1.ListItems.Add , "5bitsentinel", "Track 3 Start Sentinel"
        ListView1.ListItems.Add , "endsentinel", "End Sequence"
        temp = conv("H21")
        ListView1.ListItems.Item(1).ListSubItems.Add , , temp
        temp = conv("H191")
        ListView1.ListItems.Item(2).ListSubItems.Add , , temp
        temp = conv("H13")
        ListView1.ListItems.Item(3).ListSubItems.Add , , temp
        temp = conv("H192")
        ListView1.ListItems.Item(4).ListSubItems.Add , , temp
        temp = conv("H17")
        ListView1.ListItems.Item(5).ListSubItems.Add , , temp
        ListView1.ListItems.Item(6).ListSubItems.Add , , MCM.conv("H61") & MCM.conv("H64") & MCM.conv("H66")
        ListView1.ListItems.Item(7).ListSubItems.Add , , MCM.conv("H62") & MCM.conv("H67")
        ListView1.ListItems.Item(8).ListSubItems.Add , , MCM.conv("H63") & MCM.conv("H65") & MCM.conv("H68")
        ListView1.ListItems.Item(9).ListSubItems.Add , , MCM.conv("H69") & MCM.conv("H6A") & MCM.conv("H6B")
    End If
    If Node.Key = "Child5" Then
        ListView1.ListItems.Clear
        ListView1.ListItems.Add , "t1prefix", "Track 1 Prefix"
        ListView1.ListItems.Add , "t1suffix", "Track 1 Suffix"
        ListView1.ListItems.Add , "t2prefix", "Track 2 Prefix"
        ListView1.ListItems.Add , "t2suffix", "Track 2 Suffix"
        ListView1.ListItems.Add , "t3prefix", "Track 3 Prefix"
        ListView1.ListItems.Add , "t3suffix", "Track 3 Suffix"
        ListView1.ListItems.Add , "preamble", "Preamble"
        ListView1.ListItems.Add , "postamble", "Postamble"
        temp = conv("H34")
        ListView1.ListItems.Item(1).ListSubItems.Add , , temp
        temp = conv("H37")
        ListView1.ListItems.Item(2).ListSubItems.Add , , temp
        temp = conv("H35")
        ListView1.ListItems.Item(3).ListSubItems.Add , , temp
        temp = conv("H38")
        ListView1.ListItems.Item(4).ListSubItems.Add , , temp
        temp = conv("H36")
        ListView1.ListItems.Item(5).ListSubItems.Add , , temp
        temp = conv("H39")
        ListView1.ListItems.Item(6).ListSubItems.Add , , temp
        temp = conv("HD2")
        ListView1.ListItems.Item(7).ListSubItems.Add , , temp
        temp = conv("HD3")
        ListView1.ListItems.Item(8).ListSubItems.Add , , temp
    End If
    
End Sub

Public Function conv(ByRef X As String) As String
    Dim z As Integer
    If X = "H10" Then
    ElseIf X = "H11" Then
        If (H11 = "30") Then
            conv = "OFF"
        ElseIf (H11 = "31") Then
            conv = "LOW"
        ElseIf (H11 = "32") Then
            conv = "HIGH"
        ElseIf (H11 = "33") Then
            conv = "Quick HIGH"
        ElseIf (H11 = "34") Then
            conv = "Quick LOW"
        End If
    ElseIf X = "H12" Then
        If (H12 = "30") Then
            conv = "2 ms"
        ElseIf (H12 = "31") Then
            conv = "5 ms"
        ElseIf (H12 = "32") Then
            conv = "10 ms"
        ElseIf (H12 = "33") Then
            conv = "20 ms"
        ElseIf (H12 = "34") Then
            conv = "50 ms"
        ElseIf (H12 = "35") Then
            conv = "100 ms"
        End If
    ElseIf X = "H13" Then
        If (H13 = "30") Then
            conv = "Any Track"
        ElseIf (H13 = "31") Then
            conv = "Track 1"
        ElseIf (H13 = "32") Then
            conv = "Track 2"
        ElseIf (H13 = "33") Then
            conv = "Track 1 And 2"
        ElseIf (H13 = "34") Then
            conv = "Track 3"
        ElseIf (H13 = "35") Then
            conv = "Track 1 And 3"
        ElseIf (H13 = "36") Then
            conv = "Track 2 And 3"
        ElseIf (H13 = "37") Then
            conv = "All Tracks"
        ElseIf (H13 = "38") Then
            conv = "Track 1 Or 2"
        ElseIf (H13 = "39") Then
            conv = "Track 2 Or 3"
        End If
    ElseIf X = "H14" Then
        conv = CInt("&H" & H14) 'Hex$(H14)
    ElseIf X = "H17" Then
        If (CInt("&H" & H17) >= 40 And CInt("&H" & H17) < 127) Then
            conv = Chr$(Val("&H" & H17))
        Else
            conv = "<" & H17 & ">"
        End If
    ElseIf X = "H190" Then
        If ((("&H" & H19) - 48) < 8) Then
            conv = "Ctrl Key Output"
        Else
            conv = "Alt Key Output"
        End If
    ElseIf X = "H191" Then
        If ((("&H" & H19) - 48 + 1) Mod 2 = 1) Then
            conv = "No"
        Else
            conv = "Yes"
        End If
    ElseIf X = "H192" Then
        If ((("&H" & MCM.H19) - 48) Mod 4 > 1) Then
            conv = "Yes"
        Else
            conv = "No"
        End If
    ElseIf X = "H1A" Then
        If (H1A = "30") Then
            conv = "Enable"
        ElseIf (H1A = "31") Then
            conv = "Disable"
        End If
    ElseIf X = "H1D" Then
        If (H1D = "30") Then
            conv = "Raw data"
        ElseIf (H1D = "31") Then
            conv = "Both"
        ElseIf (H1D = "32") Then
            conv = "Forward"
        ElseIf (H1D = "33") Then
            conv = "Reverse"
        End If
    ElseIf X = "H21" Then
        If (Val("&H" & H21) >= 32 And Val("&H" & H21) < 127) Then
            conv = Chr$(Val("&H" & H21))
        Else
            conv = "<" & H21 & ">"
        End If
    ElseIf X = "H23" Then
        If (H23 = "30") Then
            conv = "USB HID"
        ElseIf (H23 = "31") Then
            conv = "Other HID Format"
        ElseIf (H23 = "38") Then
            conv = "USB KB"
        End If
    ElseIf X = "H24" Then
        If (H24 = "30") Then
            conv = "US"
        ElseIf (H24 = "31") Then
            conv = "Swiss"
        ElseIf (H24 = "32") Then
            conv = "Swedish"
        ElseIf (H24 = "33") Then
            conv = "Spanish"
        ElseIf (H24 = "34") Then
            conv = "Norwegian"
        ElseIf (H24 = "35") Then
            conv = "Italian"
        ElseIf (H24 = "36") Then
            conv = "German"
        ElseIf (H24 = "37") Then
            conv = "French"
        ElseIf (H24 = "38") Then
            conv = "Japanese"
        ElseIf (H24 = "39") Then
            conv = "UK"
        ElseIf (H24 = "3A") Then
            conv = "Universal"
        End If
    ElseIf X = "H34" Then
        conv = H34
        z = 1
        conv = ""
        If (H34 <> "00") Then
            Do While z <= Len(H34)
                If (CInt("&H" & Mid$(H34, z, 2)) >= 20 And CInt("&H" & Mid$(H34, z, 2)) < 127) Then
                    conv = conv & Chr$(Val("&H" & Mid$(H34, z, 2)))
                Else
                    conv = conv & UCase$("<" & Mid$(H34, z, 2) & ">")
                End If
                z = z + 3
            Loop
        End If
    ElseIf X = "H35" Then
        conv = H35
        z = 1
        conv = ""
        If (H35 <> "00") Then
            Do While z <= Len(H35)
                If (CInt("&H" & Mid$(H35, z, 2)) >= 20 And CInt("&H" & Mid$(H35, z, 2)) < 127) Then
                    conv = conv & Chr$(Val("&H" & Mid$(H35, z, 2)))
                Else
                    conv = conv & UCase$("<" & Mid$(H35, z, 2) & ">")
                End If
                z = z + 3
            Loop
        End If
    ElseIf X = "H36" Then
        conv = H36
        z = 1
        conv = ""
        If (H36 <> "00") Then
            Do While z <= Len(H36)
                If (CInt("&H" & Mid$(H36, z, 2)) >= 20 And CInt("&H" & Mid$(H36, z, 2)) < 127) Then
                    conv = conv & Chr$(Val("&H" & Mid$(H36, z, 2)))
                Else
                    conv = conv & UCase$("<" & Mid$(H36, z, 2) & ">")
                End If
                z = z + 3
            Loop
        End If
    ElseIf X = "H37" Then
        conv = H37
        z = 1
        conv = ""
        If (H37 <> "00") Then
            Do While z <= Len(H37)
                If (CInt("&H" & Mid$(H37, z, 2)) >= 20 And CInt("&H" & Mid$(H37, z, 2)) < 127) Then
                    conv = conv & Chr$(Val("&H" & Mid$(H37, z, 2)))
                Else
                    conv = conv & UCase$("<" & Mid$(H37, z, 2) & ">")
                End If
                z = z + 3
            Loop
        End If
    ElseIf X = "H38" Then
        conv = H38
        z = 1
        conv = ""
        If (H38 <> "00") Then
            Do While z <= Len(H38)
                If (CInt("&H" & Mid$(H38, z, 2)) >= 20 And CInt("&H" & Mid$(H38, z, 2)) < 127) Then
                    conv = conv & Chr$(Val("&H" & Mid$(H38, z, 2)))
                Else
                    conv = conv & UCase$("<" & Mid$(H38, z, 2) & ">")
                End If
                z = z + 3
            Loop
        End If
    ElseIf X = "H39" Then
        conv = H39
        z = 1
        conv = ""
        If (H39 <> "00") Then
            Do While z <= Len(H39)
                If (CInt("&H" & Mid$(H39, z, 2)) >= 20 And CInt("&H" & Mid$(H39, z, 2)) < 127) Then
                    conv = conv & Chr$(Val("&H" & Mid$(H39, z, 2)))
                Else
                    conv = conv & UCase$("<" & Mid$(H39, z, 2) & ">")
                End If
                z = z + 3
            Loop
        End If
    ElseIf X = "H49" Then
        conv = H49
    ElseIf X = "H4A" Then
        conv = H4A
    ElseIf X = "H4B" Then
        If (CInt("&H" & H4B) >= 20 And CInt("&H" & H4B) < 127) Then
            conv = Chr$(Val("&H" & H4B))
        Else
            conv = H4B
        End If
    ElseIf X = "H4D" Then
        If (H4D = "30") Then
            conv = "Standard"
        ElseIf (H4D = "31") Then
            conv = "OPOS"
        End If
    ElseIf X = "H50" Then
        If (H50 = "30") Then
            conv = "Yes"
        ElseIf (H4D = "31") Then
            conv = "No"
        End If
    ElseIf X = "H55" Then
        If (H50 = "30") Then
            conv = "Yes"
        ElseIf (H4D = "31") Then
            conv = "No"
        End If
    ElseIf X = "H58" Then
        If (H58 = "30") Then
            conv = "Fixed"
        ElseIf (H58 = "31") Then
            conv = "Non Fixed"
        End If
    ElseIf X = "H5C" Then
        If (H5C = "30") Then
            conv = "No Track Hash"
        ElseIf (H5C = "31") Then
            conv = "Track 1 Hash"
        ElseIf (H5C = "32") Then
            conv = "Track 2 Hash"
        ElseIf (H5C = "33") Then
            conv = "Track 1 & 2 Hash"
        ElseIf (H5C = "34") Then
            conv = "Track 3 Hash"
        ElseIf (H5C = "35") Then
            conv = "Track 1 & 3 Hash"
        ElseIf (H5C = "36") Then
            conv = "Track 2 & 3 Hash"
        ElseIf (H5C = "37") Then
            conv = "All Trash Hash"
        End If
    ElseIf X = "H5D" Then
        If (H5D = "30") Then
            conv = "Hex"
        ElseIf (H5D = "31") Then
            conv = "No Hex"
        End If
    ElseIf X = "H60" Then
        If (H60 = "30") Then
            conv = "Without"
        ElseIf (H60 = "31") Then
            conv = "With"
        End If
    ElseIf X = "H61" Then
        If H61 = "" Then
            H61 = "00"
        End If
        If (CInt("&H" & H61) >= 32 And CInt("&H" & H61) < 127) Then
            conv = Chr$(Val("&H" & H61))
        Else
            conv = "<" & H61 & ">"
        End If
    ElseIf X = "H62" Then
        If H62 = "" Then
            H62 = "00"
        End If
        If (CInt("&H" & H62) >= 32 And CInt("&H" & H62) < 127) Then
            conv = Chr$(Val("&H" & H62))
        Else
            conv = "<" & H62 & ">"
        End If
    ElseIf X = "H63" Then
        If H63 = "" Then
            H63 = "00"
        End If
        If (CInt("&H" & H63) >= 32 And CInt("&H" & H63) < 127) Then
            conv = Chr$(Val("&H" & H63))
        Else
            conv = "<" & H63 & ">"
        End If
    ElseIf X = "H64" Then
        If H64 = "" Then
            H64 = "00"
        End If
        If (CInt("&H" & H64) >= 32 And CInt("&H" & H64) < 127) Then
            conv = Chr$(Val("&H" & H64))
        Else
            conv = "<" & H64 & ">"
        End If
    ElseIf X = "H65" Then
        If H65 = "" Then
            H65 = "00"
        End If
        If (CInt("&H" & H65) >= 32 And CInt("&H" & H65) < 127) Then
            conv = Chr$(Val("&H" & H65))
        Else
            conv = "<" & H65 & ">"
        End If
    ElseIf X = "H66" Then
        If H66 = "" Then
            H66 = "00"
        End If
        If (CInt("&H" & H66) >= 32 And CInt("&H" & H66) < 127) Then
            conv = Chr$(Val("&H" & H66))
        Else
            conv = "<" & H66 & ">"
        End If
    ElseIf X = "H67" Then
        If H67 = "" Then
            H67 = "00"
        End If
        If (CInt("&H" & H67) >= 32 And CInt("&H" & H67) < 127) Then
            conv = Chr$(Val("&H" & H67))
        Else
            conv = "<" & H67 & ">"
        End If
    ElseIf X = "H68" Then
        If H68 = "" Then
            H68 = "00"
        End If
        If (CInt("&H" & H68) >= 32 And CInt("&H" & H68) < 127) Then
            conv = Chr$(Val("&H" & H68))
        Else
            conv = "<" & H68 & ">"
        End If
    ElseIf X = "H69" Then
        If H69 = "" Then
            H69 = "00"
        End If
        If (CInt("&H" & H69) >= 32 And CInt("&H" & H69) < 127) Then
            conv = Chr$(Val("&H" & H69))
        Else
            conv = "<" & H69 & ">"
        End If
    ElseIf X = "H6A" Then
        If H6A = "" Then
            H6A = "00"
        End If
        If (CInt("&H" & H6A) >= 32 And CInt("&H" & H6A) < 127) Then
            conv = Chr$(Val("&H" & H6A))
        Else
            conv = "<" & H6A & ">"
        End If
    ElseIf X = "H6B" Then
        If H6B = "" Then
            H6B = "00"
        End If
        If (CInt("&H" & H6B) >= 32 And CInt("&H" & H6B) < 127) Then
            conv = Chr$(Val("&H" & H6B))
        Else
            conv = "<" & H6B & ">"
        End If
    ElseIf X = "H6C" Then
        If H6C = "" Then
            H6C = "00"
        End If
        If (CInt("&H" & H6C) >= 32 And CInt("&H" & H6C) < 127) Then
            conv = Chr$(Val("&H" & H6C))
        Else
            conv = "<" & H6C & ">"
        End If
    ElseIf X = "H6D" Then
        If H6D = "" Then
            H6D = "00"
        End If
        If (CInt("&H" & H6D) >= 32 And CInt("&H" & H6D) < 127) Then
            conv = Chr$(Val("&H" & H6D))
        Else
            conv = "<" & H6D & ">"
        End If
    ElseIf X = "H6E" Then
        If H6E = "" Then
            H6E = "00"
        End If
        If (CInt("&H" & H6E) >= 32 And CInt("&H" & H6E) < 127) Then
            conv = Chr$(Val("&H" & H6E))
        Else
            conv = "<" & H6E & ">"
        End If
    ElseIf X = "H7B" Then
        If (H7B = "30") Then
            conv = "No"
        ElseIf (H7B = "31") Then
            conv = "Yes"
        End If
    ElseIf X = "H84" Then
        If (H84 = "30") Then
            conv = "Encrypt No Track"
        ElseIf (H84 = "31") Then
            conv = "Encrypt Track 1"
        ElseIf (H84 = "32") Then
            conv = "Encrypt Track 2"
        ElseIf (H84 = "33") Then
            conv = "Encrypt Track 1 & 2"
        ElseIf (H84 = "34") Then
            conv = "Encrypt Track 3"
        ElseIf (H84 = "35") Then
            conv = "Encrypt Track 1 & 3"
        ElseIf (H84 = "36") Then
            conv = "Encrypt Track 2 & 3"
        ElseIf (H84 = "37") Then
            conv = "Encrypt All Tracks"
        ElseIf (H84 = "38") Then
            conv = "Encrypt Track 3 if card type 0"
        ElseIf (H84 = "39") Then
            conv = "Encrypt Track 3 if card type 0"
        ElseIf (H84 = "3A") Then
            conv = "Encrypt Track 3 if card type 0"
        ElseIf (H84 = "3B") Then
            conv = "Encrypt Track 3 if card type 0"
        ElseIf (H84 = "3C") Then
            conv = "Encrypt Track 3 if card type 0"
        ElseIf (H84 = "3D") Then
            conv = "Encrypt Track 3 if card type 0"
        ElseIf (H84 = "3E") Then
            conv = "Encrypt Track 3 if card type 0"
        ElseIf (H84 = "3F") Then
            conv = "Encrypt Track 3 if card type 0"
        End If
    ElseIf X = "HD2" Then
        conv = HD2
        z = 1
        conv = ""
        If (HD2 <> "00") Then
            Do While z <= Len(HD2)
                If (CInt("&H" & Mid$(HD2, z, 2)) >= 20 And CInt("&H" & Mid$(HD2, z, 2)) < 127) Then
                    conv = conv & Chr$(Val("&H" & Mid$(HD2, z, 2)))
                Else
                    conv = conv & UCase$("<" & Mid$(HD2, z, 2) & ">")
                End If
                z = z + 3
            Loop
        End If
    ElseIf X = "HD3" Then
        conv = HD3
        z = 1
        conv = ""
        If (HD3 <> "00") Then
        Do While z <= Len(HD3)
            If (CInt("&H" & Mid$(HD3, z, 2)) >= 20 And CInt("&H" & Mid$(HD3, z, 2)) < 127) Then
                conv = conv & Chr$(Val("&H" & Mid$(HD3, z, 2)))
            Else
                conv = conv & UCase$("<" & Mid$(HD3, z, 2) & ">")
            End If
            z = z + 3
        Loop
        End If
    End If
        
End Function


Public Function text2cmd(ByRef X As String, ByVal Y As Integer) As String
    Dim z As Integer
    If (Len(X) = 0) Then
        text2cmd = "00"
    Else
        text2cmd = ""
        z = 1
        Do While z <= Len(X)
            If (z <> 1) Then
                text2cmd = text2cmd & "\"
            End If
            If (Mid$(X, z, 1) = "<" And Mid$(X, z + 3, 1) = ">") Then
                text2cmd = text2cmd & Mid$(X, z + 1, 2)
                z = z + 4
            Else
                text2cmd = text2cmd & (Hex$(Asc(Mid$(X, z, 1))))
                z = z + 1
            End If
            If (Y = 1) Then
                z = Len(X) + 1
            End If
            Y = Y - 1
        Loop
    End If
End Function


'This subroutine is for card reading event
Private Sub HIDTimer_Timer()

    Dim StartTime As Date
    Dim DelayTime As Date
            
    If FatalError <> "" Then
        HIDLable.Caption = "Error - " & FatalError
        Status.Label1.Caption = "Error - " & FatalError
        Exit Sub
    End If
  
                
    If HidDevice = INVALID_HANDLE_VALUE Then
        HIDLable.Caption = "Searching for reader..."
        Status.Label1.Caption = "Searching for reader..."
        connected = 0
            
        DelayTime = Timer
        Do While Timer < DelayTime + 5
            DoEvents
        Loop
        
        DetectDevice
        If HidDevice <> INVALID_HANDLE_VALUE Then
            If DeviceAttributes.ProductID = ProdID Then        '2010 SecureMag USB HID (Unitech Format)
                IDTECHFmt = True
                InitRead
            ElseIf DeviceAttributes.ProductID = ProdID2 Then   '2030 SecureMag USB KB
                IDTECHFmt = True
                'InitRead
            ElseIf DeviceAttributes.ProductID = ProdID3 Then   '0500 MS246 USB HID
                IDTECHFmt = True
                InitRead
            ElseIf DeviceAttributes.ProductID = ProdID4 Then   '0520 MS246 USB KB
                IDTECHFmt = True
                'InitRead
            Else
                FatalError = "It is an unknown reader"
                HIDLable.Caption = "Error - " & FatalError
                Status.Label1.Caption = "Error - " & FatalError
            End If
        End If
    Else
        If DeviceAttributes.ProductID = ProdID Then
            HIDLable.Caption = "Found HID Reader"
            Status.Label1.Caption = "Found USB HID Reader"
            connected = 1
        ElseIf DeviceAttributes.ProductID = ProdID2 Then
            HIDLable.Caption = "Found USB KB Reader"
            Status.Label1.Caption = "Found USB KB Reader"
            connected = 2
        ElseIf DeviceAttributes.ProductID = ProdID3 Then
            HIDLable.Caption = "Found HID Reader"
            Status.Label1.Caption = "Found USB HID Reader"
            connected = 1
        ElseIf DeviceAttributes.ProductID = ProdID4 Then
            HIDLable.Caption = "Found USB KB Reader"
            Status.Label1.Caption = "Found USB KB Reader"
            connected = 2
        Else
            HIDLable.Caption = " "
            Status.Label1.Caption = " "
        End If
        
        If (DeviceAttributes.ProductID <> ProdID2 And DeviceAttributes.ProductID <> ProdID4) Then
            If ReadInputRpt() = True Then
                HIDResult = ""
                StartTime = Timer
                Do While Timer < StartTime + 0.1
                   DoEvents
                Loop
                ShowData
            End If
        Else
            HidDevice = INVALID_HANDLE_VALUE
            DetectDevice
        End If
    End If
 End Sub
 
  'The following subroutines are for card data output in Output box
 Public Sub ShowData()

 Dim Str As String
 Dim I, j, k As Long
 Dim HexStr As String
    
    Str = ""
    
    Select Case ReadBuffer(7)
        Case 0
            Str = "Card Type is ISO" & vbCrLf & vbCrLf
        Case 1
            Str = "Card Type is AAMVA" & vbCrLf & vbCrLf
        Case 2
            Str = "Card Type is CADL" & vbCrLf & vbCrLf
        Case 3
            Str = "Card Type is BLANK" & vbCrLf & vbCrLf
        Case 4
            Str = "Card Type is OTHER" & vbCrLf & vbCrLf
    End Select
    
    If IDTECHFmt = True Then
            If (ReadBuffer(1) <> 2) Then
                j = ReadBuffer(8) * 256 + ReadBuffer(9)
                For I = 1 To j
                    If ReadBuffer(9 + I) = 13 Then
                    Str = Str & vbCrLf
                    Else
                    Str = Str & Chr(ReadBuffer(9 + I))
                    End If
                Next I
            Else
                j = ReadBuffer(3) * 256 + ReadBuffer(2)
                For I = 1 To j
                    If ReadBuffer(9 + I) = 13 Then
                    Str = Str & vbCrLf
                    Else
                    Str = Str & Chr(ReadBuffer(9 + I))
                    End If
                Next I
            End If
                
 
    Else
        For I = 8 To 337
            If ReadBuffer(I) = 13 Then
            Str = Str & vbCrLf
            ElseIf ReadBuffer(I) <> 0 Then
            Str = Str & Chr(ReadBuffer(I))
            End If
        Next I
    End If
    
    HIDResult.Text = Str
 End Sub
 
 
Public Sub SendHIDKBCommand(cmd As String)

    Dim Temp1, Temp2 As String
    Dim I As Integer
    Dim HasMore As Boolean
    
    
    'Check for any fatal errors.
    If FatalError <> "" Then
        HIDLable.Caption = "Error - " & FatalError
        Status.Label1.Caption = "Error - " & FatalError
        Exit Sub
    End If
    
    'See if the correct device has been detected
    If HidDevice = INVALID_HANDLE_VALUE Then
    'See if the correct device is attached
    DetectDevice
        If HidDevice = INVALID_HANDLE_VALUE Then
            HIDLable.Caption = "Searching for reader..."
            Status.Label1.Caption = "Searching for reader..."
            connected = 0
            Exit Sub
        End If
        If FatalError <> "" Then
            HIDLable.Caption = "Error - " & FatalError
            Status.Label1.Caption = "Error - " & FatalError
            Exit Sub
        End If
    End If
      
  
'Initialize command data
    InitCmd
' Interpret message set up the transmit data
    If Not FillToRdrBfr(cmd) Then
        'GoToMsgTxt
        Exit Sub
    End If
    FillTrxBfr
    SendCmd
    While (HasMoreToRdr) ' Send more request if not finished
        FillTrxBfr
        SendCmd
    Wend
    
    'CompleteString.Caption = HexStrToCharStr(ToRdrBfr, ToRdrBfrLen)
    
    Sleep 300
    If ToRdrBfr(2) = 82 And ToRdrBfr(3) = 31 Then
    HasMore = True
    Temp1 = ""
    GetResponse
    While (HasMore)
        Temp1 = Temp1 & Mid(ByteArrayToHexStr(FtrRptRcvBfr, Capabilities.FeatureReportByteLength), 5) & " "
        GetResponse
        HasMore = False
        For I = 2 To Capabilities.FeatureReportByteLength - 1
            If FtrRptRcvBfr(I) <> 0 Then
            HasMore = True
            End If
        Next I
    Wend
    HIDResult.Text = Temp1
    ElseIf ToRdrBfr(2) = 82 And ToRdrBfr(3) = 34 Then
    HasMore = True
    HIDResult.Text = ""
    GetResponse
    Temp1 = ByteStrToChar(FtrRptRcvBfr, 3, Capabilities.FeatureReportByteLength - 1)
    HIDResult.Text = HIDResult.Text & Temp1
    While (HasMore)
        GetResponse
        HasMore = False
        For I = 1 To Capabilities.FeatureReportByteLength - 1
            If FtrRptRcvBfr(I) <> 3 Then
            HasMore = True
            Else
            HasMore = False
            Exit For
            End If
        Next I
        If (HasMore) Then
        Temp1 = ByteStrToChar(FtrRptRcvBfr, 1, Capabilities.FeatureReportByteLength - 1)
        Else
        Temp1 = ByteStrToChar(FtrRptRcvBfr, 1, I - 1)
        End If
        HIDResult.Text = HIDResult.Text & Temp1
    Wend
    Else
    GetResponse
    HIDResult.Text = "\" & Mid(ByteArrayToHexStr(FtrRptRcvBfr, Capabilities.FeatureReportByteLength), 5, 2)
    End If

End Sub
 
Private Sub Form_Unload(Cancel As Integer)
    HIDTimer.Enabled = False
    CloseDevice
    CloseUSB
    Unload Edit
    Unload Status
End Sub

Private Sub upload_Click()
    IDvalue = 0
    Status.Show vbModeless, Me
End Sub

Private Sub dnload_Click()
    IDvalue = 1
    Status.Show vbModeless, Me
End Sub

Public Function parsecmd(ByVal temp As String) As Boolean
Dim l As Integer
Dim X As Integer
Dim Y As Integer
Dim z As Integer

X = 1
Y = 0
z = 0
If (Mid$(temp, 1, 2) = "06" Or Mid$(temp, 1, 3) = "\53") Then


Do While X < Len(temp) - 1
If Mid$(temp, 1, 3) = "\53" And X = 1 Then
        X = X + 4
        z = 1
'        MsgBox Mid$(temp, 1, 3) & "|" & x
Else
    If (Mid$(temp, X, 2) = "02" And z = 0) Then
        z = 1
        X = X + 3
        'MsgBox ("enter")
    Else
        X = X + 3
    End If
    If (Mid$(temp, X, 2) = "03" And z = 1) Then
        z = 0
        X = Len(temp) + 1
        'MsgBox ("exit")
    End If
End If
    If (z = 1) Then
    
        'MsgBox CInt(Val("&H" & Mid$(temp, X + 3, 2))) & "|" & Mid$(temp, X, 2)
        ' Val("&H" & Mid$(temp, X + 3, 2))
        Y = 0
        Select Case Mid$(temp, X, 2)
        Case "10"
            H10 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H10 = H10 & "\"
                End If
                H10 = H10 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "11"
            H11 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H11 = H11 & "\"
                End If
                H11 = H11 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "12"
            H12 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H12 = H12 & "\"
                End If
                H12 = H12 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "13"
            H13 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H13 = H13 & "\"
                End If
                H13 = H13 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "14"
            H14 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H14 = H14 & "\"
                End If
                H14 = H14 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "15"
            H15 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H15 = H15 & "\"
                End If
                H15 = H15 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "16"
            H16 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H16 = H16 & "\"
                End If
                H16 = H16 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "17"
            H17 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H17 = H17 & "\"
                End If
                H17 = H17 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "19"
            H19 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H19 = H19 & "\"
                End If
                H19 = H19 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "1A"
            H1A = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H1A = H1A & "\"
                End If
                H1A = H1A & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "1B"
            H1B = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H1B = H1B & "\"
                End If
                H1B = H1B & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "1D"
            H1D = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H1D = H1D & "\"
                End If
                H1D = H1D & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "1F"
            H1F = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H1F = H1F & "\"
                End If
                H1F = H1F & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "21"
            H21 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H21 = H21 & "\"
                End If
                H21 = H21 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "22"
            H22 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H22 = H22 & "\"
                End If
                H22 = H22 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "23"
            H23 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H23 = H23 & "\"
                End If
                H23 = H23 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "24"
            H24 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H24 = H24 & "\"
                End If
                H24 = H24 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "25"
            H25 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H25 = H25 & "\"
                End If
                H25 = H25 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "34"
            H34 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H34 = H34 & "\"
                ElseIf (Val("&H" & Mid$(temp, X + 3, 2)) > 1) Then
                    Y = Y + 1
                End If
                H34 = H34 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            If Y = 2 Then
'                H34 = "00"
            End If
            X = X + 3 * Y + 3
        Case "35"
            H35 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H35 = H35 & "\"
                ElseIf (Val("&H" & Mid$(temp, X + 3, 2)) > 1) Then
                    Y = Y + 1
                End If
                H35 = H35 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "36"
            H36 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H36 = H36 & "\"
                ElseIf (Val("&H" & Mid$(temp, X + 3, 2)) > 1) Then
                    Y = Y + 1
                End If
                H36 = H36 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "37"
            H37 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H37 = H37 & "\"
                ElseIf (Val("&H" & Mid$(temp, X + 3, 2)) > 1) Then
                    Y = Y + 1
                End If
                H37 = H37 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "38"
            H38 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H38 = H38 & "\"
                ElseIf (Val("&H" & Mid$(temp, X + 3, 2)) > 1) Then
                    Y = Y + 1
                End If
                H38 = H38 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "39"
            H39 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H39 = H39 & "\"
                ElseIf (Val("&H" & Mid$(temp, X + 3, 2)) > 1) Then
                    Y = Y + 1
                End If
                H39 = H39 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "41"
            H41 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H41 = H41 & "\"
                End If
                H41 = H41 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "42"
            H42 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H42 = H42 & "\"
                End If
                H42 = H42 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "43"
            H43 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H43 = H43 & "\"
                End If
                H43 = H43 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "44"
            H44 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H44 = H44 & "\"
                End If
                H44 = H44 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "45"
            H45 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H45 = H45 & "\"
                End If
                H45 = H45 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "47"
            H47 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H47 = H47 & "\"
                End If
                H47 = H47 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "48"
            H48 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H48 = H48 & "\"
                End If
                H48 = H48 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "49"
            H49 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H49 = H49 & "\"
                End If
                H49 = H49 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "4A"
            H4A = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H4A = H4A & "\"
                End If
                H4A = H4A & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "4B"
            H4B = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H4B = H4B & "\"
                End If
                H4B = H4B & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "4C"
            H4C = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H4C = H4C & "\"
                End If
                H4C = H4C & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "4D"
            H4D = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H4D = H4D & "\"
                End If
                H4D = H4D & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "4E"
            H4E = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H4E = H4E & "\"
                End If
                H4E = H4E & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "50"
            H50 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H50 = H50 & "\"
                End If
                H50 = H50 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "54"
            H54 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H54 = H54 & "\"
                End If
                H54 = H54 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "55"
            H55 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H55 = H55 & "\"
                End If
                H55 = H55 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "56"
            H56 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H56 = H56 & "\"
                End If
                H56 = H56 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "57"
            H57 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H57 = H57 & "\"
                End If
                H57 = H57 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "58"
            H58 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H58 = H58 & "\"
                End If
                H58 = H58 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "5C"
            H5C = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H5C = H5C & "\"
                End If
                H5C = H5C & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "5D"
            H5D = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H5D = H5D & "\"
                End If
                H5D = H5D & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "60"
            H60 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H60 = H60 & "\"
                End If
                H60 = H60 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "61"
            H61 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H61 = H61 & "\"
                End If
                H61 = H61 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "62"
            H62 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H62 = H62 & "\"
                End If
                H62 = H62 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "63"
            H63 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H63 = H63 & "\"
                End If
                H63 = H63 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "64"
            H64 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H64 = H64 & "\"
                End If
                H64 = H64 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "65"
            H65 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H65 = H65 & "\"
                End If
                H65 = H65 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "66"
            H66 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H66 = H66 & "\"
                End If
                H66 = H66 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "67"
            H67 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H67 = H67 & "\"
                End If
                H67 = H67 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "68"
            H68 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H68 = H68 & "\"
                End If
                H68 = H68 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "69"
            H69 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H69 = H69 & "\"
                End If
                H69 = H69 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "6A"
            H6A = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H6A = H6A & "\"
                End If
                H6A = H6A & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "6B"
            H6B = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H6B = H6B & "\"
                End If
                H6B = H6B & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "6C"
            H6C = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H6C = H6C & "\"
                End If
                H6C = H6C & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "6D"
            H6D = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H6D = H6D & "\"
                End If
                H6D = H6D & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "6E"
            H6E = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H6E = H6E & "\"
                End If
                H6E = H6E & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "72"
            H72 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H72 = H72 & "\"
                End If
                H72 = H72 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "73"
            H73 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H73 = H73 & "\"
                End If
                H73 = H73 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "77"
            H77 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H77 = H77 & "\"
                End If
                H77 = H77 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "7A"
            H7A = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H7A = H7A & "\"
                End If
                H7A = H7A & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "7B"
            H7B = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H7B = H7B & "\"
                End If
                H7B = H7B & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "7E"
            H7E = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H7E = H7E & "\"
                End If
                H7E = H7E & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "84"
            H84 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H84 = H84 & "\"
                End If
                H84 = H84 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "85"
            H85 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H85 = H85 & "\"
                End If
                H85 = H85 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "86"
            H86 = ""
            Do While Y < CInt(Val("&H" & Mid$(temp, X + 3, 2)))
                If Y <> 0 Then
                    H86 = H86 & "\"
                End If
                H86 = H86 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "D2"
            HD2 = ""
            'MsgBox (CInt(Mid$(temp, X + 3, 2)))
            Do While Y < Val("&H" & Mid$(temp, X + 3, 2))
                If Y <> 0 Then
                    HD2 = HD2 & "\"
                ElseIf (Val("&H" & Mid$(temp, X + 3, 2)) > 1) Then
                    Y = Y + 1
                End If
                HD2 = HD2 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case "D3"
            HD3 = ""
            'MsgBox (Val("&H" & Mid$(temp, X + 3, 2)))
            Do While Y < Val("&H" & Mid$(temp, X + 3, 2))
                If Y <> 0 Then
                    HD3 = HD3 & "\"
                ElseIf (Val("&H" & Mid$(temp, X + 3, 2)) > 1) Then
                    Y = Y + 1
                End If
                HD3 = HD3 & Mid$(temp, X + 6 + (3 * Y), 2)
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
        Case Else
        'MsgBox Mid$(temp, X + 9 + 3 * Y, 2) & "|" & X
            Do While Y < Val("&H" & Mid$(temp, X + 3, 2))
                Y = Y + 1
            Loop
            X = X + 3 * Y + 3
            'MsgBox X
        End Select

        
    End If
Loop
parsecmd = True
Else
parsecmd = False
End If
End Function

Public Sub inittree()

Dim nodRoot As Node
Dim nodx As Node
'Set TreeView1.ImageList = ImageList1
Set nodRoot = TreeView1.Nodes.Add(, , "Root", "Current Settings")
nodRoot.Image = 1
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child1", "Beeps and Delay")
nodx.Image = 2
nodx.SelectedImage = 3
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child2", "Keyboard")
nodx.Image = 2
nodx.SelectedImage = 3
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child3", "USB")
nodx.Image = 2
nodx.SelectedImage = 3
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child4", "Magnetic Reader")
nodx.Image = 2
nodx.SelectedImage = 3
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child5", "Data Editing")
nodx.Image = 2
nodx.SelectedImage = 3

nodRoot.Expanded = True
End Sub
Public Function fGetSpecialFolder(ByVal CSIDL As Long) As String
    'This function will find My documents path.
    'value       Result
    '2           C:\Documents and Settings\<USERNAME>\Start Menu\Programs
    '5           C:\Documents and Settings\<USERNAME>\My Documents
    '6           C:\Documents and Settings\<USERNAME>\Favorites
    '7           C:\Documents and Settings\<USERNAME>\Start Menu\Programs\Startup
    '8           C:\Documents and Settings\<USERNAME>\Recent
    '9           C:\Documents and Settings\<USERNAME>\SendTo
    '11          C:\Documents and Settings\<USERNAME>\Start Menu
    '13          C:\Documents and Settings\scsrinivasan\My Documents\My Music
    '16          C:\Documents and Settings\<USERNAME>\Desktop
    '19          C:\Documents and Settings\<USERNAME>\NetHood
    '20          C:\WINNT\Fonts
    '21          C:\Documents and Settings\<USERNAME>\Templates
    '22          C:\Documents and Settings\All Users\Start Menu
    '23          C:\Documents and Settings\All Users\Start Menu\Programs
    '24          C:\Documents and Settings\All Users\Start Menu\Programs\Startup
    '25          C:\Documents and Settings\All Users\Desktop
    '26          C:\Documents and Settings\<USERNAME>\Application Data
    '27          C:\Documents and Settings\<USERNAME>\PrintHood
    '28          C:\Documents and Settings\<USERNAME>\Local Settings\Application Data
    '31          C:\Documents and Settings\All Users\Favorites
    '32          C:\Documents and Settings\<USERNAME>\Local Settings\Temporary Internet Files
    '33          C:\Documents and Settings\<USERNAME>\Cookies
    '34          C:\Documents and Settings\<USERNAME>\Local Settings\History
    '35          C:\Documents and Settings\All Users\Application Data
    '36          C:\WINNT37          C:\WINNT\system32
    '38          C:\Program Files
    '39          C:\Data\My Pictures
    '40          C:\Documents and Settings\<USERNAME>
    '41          C:\WINNT\system32
    '43          C:\Program Files\Common Files
    '45          C:\Documents and Settings\All Users\Templates
    '46          C:\Documents and Settings\All Users\Documents
    '47          C:\Documents and Settings\All Users\Start Menu\Programs\Administrative Tools
    '48          C:\Documents and Settings\<USERNAME>\Start Menu\Programs\Administrative Tools
    Dim sPath As String
    Dim IDL As ITEMIDLIST

    On Error GoTo fGetSpecialFolder_Error

    fGetSpecialFolder = ""
    If SHGetSpecialFolderLocation(0, CSIDL, IDL) = 0 Then
        sPath = Space$(MAX_PATH)
        If SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath) Then
            fGetSpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1) & ""
        End If
    End If

    On Error GoTo 0
    Exit Function

fGetSpecialFolder_Error:
    Err.Clear
    Resume Next
End Function

